---
import type { FriendLinkSection } from "@/data/friend-links";

const { sections } = Astro.props as { sections: FriendLinkSection[] };
---

{sections.map((section) => (
  <>
    <h2>{section.title}</h2>
    <div class="friend-links-grid">
      {section.items.map((item) => (
        <div class="friend-link-card">
          <a href={item.url} target="_blank">
            <div class="card-avatar">
              <img src={item.avatar} alt={item.title} />
            </div>
            <h3 class="card-title">{item.title}</h3>
            <p class="card-desc">{item.desc}</p>
          </a>
        </div>
      ))}
    </div>
  </>
))}

<style>
.friend-links-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 2rem;
    justify-items: center;
    padding: 2rem 0;
}

.friend-link-card {
    text-align: center;
    transition: transform 0.25s ease;
    width: 100%;
}

.friend-link-card:hover {
    transform: translateY(-4px);
}

.friend-link-card a {
    text-decoration: none !important;
    color: inherit;
    display: block;
    padding-top: 0.5rem;
}

.card-avatar {
    width: 72px;
    height: 72px;
    border-radius: 16px;
    overflow: hidden;
    margin: 0 auto 0.75rem;
    box-shadow: 0 2px 6px rgba(0,0,0,0.08);
    transition: transform 0.3s ease;
}

.friend-link-card:hover .card-avatar {
    transform: scale(1.05);
}

.card-avatar img {
    width: 100%;
    height: 100%;
    margin:0;
    padding:0;
    pointer-events: none;
}

.card-title {
    font-size: 1rem;
    font-weight: 600;
    margin: 0.25rem 0;
}

.card-desc {
    font-size: 0.70rem;
    color:  #808080;
    margin: 0;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}

@media (max-width: 768px) {
    .friend-links-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .card-avatar {
        width: 70px;
        height: 70px;
    }

    .card-info {
        padding: 0.875rem 1rem;
    }
}

:root.dark .friend-link-card {
    border-color: #333;
}

:root.dark .friend-link-card:hover {
    box-shadow: 0 8px 25px rgba(255, 255, 255, 0.05);
}

:root.dark .card-desc {
    color: #FFFFFF;
}
</style>